#coding=utf-8

import os, time, glob

from PyQt4.QtGui import *
from PyQt4.QtCore import *

import lonote.translate as translate
import lonote.oldnote as oldnote
import lonote.path as path
import lonote.dialog as dialog

cssDir = path.fix.cssDir

class LoCfgDialog(QDialog):
    '''LoNote設定視窗'''
    def __init__(self, parent = None):
        '''替Layout進行初始化'''
        super().__init__(parent, Qt.Dialog)
        #宣告與初始化
        self.parent = parent
        self.status = None
        self.setWindowTitle(_('Configure your LoNote'))
        self.acceptButton = QPushButton(_('Confirm'))
        self.acceptButton.pressed.connect(self.accept)

        #初始化第一頁項目
        self.vcsEnable = QCheckBox()
        self.vcsPeriod = QSpinBox()
        self.vcsPeriod.setSingleStep(1)
        self.vcsPeriod.setMaximum(744)
        self.vcsPeriod.setMinimum(0)
        self.vcsLenChange = QSpinBox()
        self.vcsLenChange.setSingleStep(50)
        self.vcsLenChange.setMaximum(100000000)
        self.vcsLenChange.setMinimum(0)
        self.vcsLevenshtein = QCheckBox()
        self.autoRemoveUnusedEmbeddedFiles = QCheckBox()
        self.vacuumButton = QPushButton(_('Vacuum'))
        self.vacuumButton.pressed.connect(self.vacuum)
        self.clearAllHistoryButton = QPushButton(_('clear'))
        self.clearAllHistoryButton.pressed.connect(self.clearAllHistory)
        self.autosavePeriod = QSpinBox()
        self.autosavePeriod.setSingleStep(10)
        self.autosavePeriod.setMaximum(100000000)
        self.autosavePeriod.setMinimum(0)

        #初始化第二頁項目
        #時間預覽欄初始化
        showTime = QLabel()

        def showCurrentTime(fmt):
            showTime.setText('<i>' + time.strftime(fmt, time.localtime()) + '</i>')

        class cfgLineEdit_Time(QLineEdit):
            def focusInEvent(self, event):
                super().focusInEvent(event)
                showCurrentTime(self.text())

        #時間格式欄初始化
        self.creTime = cfgLineEdit_Time()
        self.modTime = cfgLineEdit_Time()
        self.hisTime = cfgLineEdit_Time()
        self.insDate = cfgLineEdit_Time()
        self.insTime = cfgLineEdit_Time()
        self.creTime.textEdited.connect(showCurrentTime)
        self.modTime.textEdited.connect(showCurrentTime)
        self.hisTime.textEdited.connect(showCurrentTime)
        self.insTime.textEdited.connect(showCurrentTime)
        self.insDate.textEdited.connect(showCurrentTime)

        #初始化第三頁項目

        showIT = QLabel() #innerTitle格式的預覽窗
        showIT.setWordWrap(True)

        def showInnerTitle(fmt):
            fmt = fmt.replace('{$NOTENAME}',_('NoteName'))
            fmt = fmt.replace('{$PARENTNAME}',_('ParentNoteName'))
            showIT.setText(fmt)

        class cfgLineEdit_InnerTitle(QLineEdit):
            def focusInEvent(self, event):
                super().focusInEvent(event)
                showInnerTitle(self.text())

        self.showInnerTitle = QCheckBox()
        self.innerTitleFormat = cfgLineEdit_InnerTitle()
        self.innerTitleFormat.textEdited.connect(showInnerTitle)
        self.showInstantCharcount = QCheckBox()
        self.showCharcount = QCheckBox()
        self.traceScrollPos = QCheckBox()
        self.dontRefreshListview = QCheckBox()
        self.useCSS = QCheckBox()
        self.selectCSS = QComboBox()
        self.editCSSButton = QPushButton(_('edit CSS'))
        self.editCSSButton.pressed.connect(self.editCSS)
        self.language = QComboBox()
        self.font = QComboBox()
        self.textMultiplier = QDoubleSpinBox()
        self.textMultiplier.setSingleStep(0.05)
        self.textMultiplier.setMaximum(10)
        self.textMultiplier.setMinimum(0.05)

        #初始化第四頁項目
        self.exportEditorFont = QCheckBox()
        self.exportToHTMLWhenClose = QCheckBox()
        self.openAfterExportToHTML = QCheckBox()
        self.useMultiprocessing = QCheckBox()
        self.convertButton = QPushButton(_('Start!'))
        self.convertButton.pressed.connect(self.convert)

        #初始化第五頁項目
        #插入圖片預覽欄初始化
        showImage = QLabel()
        showImage.setOpenExternalLinks(True)
        showImage.setTextFormat(Qt.RichText)
        showImage.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)
        showImage.setMargin(5)
        showImage.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)
        showImage.setLineWidth(2)

        def showCurrentImage(imageStr):
            string = imageStr.replace('{$IMAGE}', '<img src="{$FILEPATH}">')
            string = string.replace('{$FILENAME}', os.path.basename(path.icons.about))
            string = string.replace('{$FILEPATH}', path.icons.about)
            showImage.setText(string)

        class cfgLineEdit_Img(QLineEdit):
            def focusInEvent(self, event):
                super().focusInEvent(event)
                showCurrentImage(self.text())

        #插入圖片設定項目初始化
        self.insImage = cfgLineEdit_Img()
        self.insImage.textChanged.connect(showCurrentImage)
        self.insImageWidth = QSpinBox()
        self.insImageWidth.setSingleStep(100)
        self.insImageWidth.setMinimum(0)
        self.insImageWidth.setMaximum(10000)
        self.insImageSrcResizeEnable = QCheckBox()
        self.insImageSrcResizeQuality = QSpinBox()
        self.insImageSrcResizeQuality.setSingleStep(1)
        self.insImageSrcResizeQuality.setMinimum(-1)
        self.insImageSrcResizeQuality.setMaximum(100)

        #鋪設第1頁Layout : Data
        lay1 = QFormLayout()
        #鋪設VCS用的GroupBox與Layout
        lay1_1 = QFormLayout()

        #lay1_1.addRow(QLabel(_('Configure your LoNote\'s version control system.')))
        lay1_1.addRow(_('Version control enable:'), self.vcsEnable)
        lay1_1.addRow(_('Backup period (hours):'), self.vcsPeriod)
        lay1_1.addRow(_('Backup period (chars):'), self.vcsLenChange)
        lay1_1.addRow(_('Use Levenshtein distance:'), self.vcsLevenshtein)
        lay1_1.addRow(_('Clear current book\'s all history:') ,self.clearAllHistoryButton)
        groupBox1_1 = QGroupBox(_('Version Control'))
        groupBox1_1.setLayout(lay1_1)
        #鋪設第1頁總Layout
        lay1.addRow(groupBox1_1)
        lay1.addRow(_('Vacuum book\'s database:'), self.vacuumButton)
        lay1.addRow(_('Autosave period (seconds):'), self.autosavePeriod)
        lay1.addRow(_('Auto-removed unused Image files:'), self.autoRemoveUnusedEmbeddedFiles)
        page1 = QWidget()
        page1.setLayout(lay1)

        #鋪設第2頁Layout : Time Format
        #鋪設時間格式用的GroupBox與Layout
        lay2_1 = QFormLayout()
        label2_0 = QLabel(_('You can find all time format in <a href="http://docs.python.org/py3k/library/time.html#time.strftime">here</a>.'))
        label2_0.setOpenExternalLinks(True)
        label2_0.setWordWrap(True)
        label2_0.setTextFormat(Qt.RichText)
        lay2_1.addRow(label2_0)
        lay2_1.addRow(_('Note created:'), self.creTime)
        lay2_1.addRow(_('Note modified:'), self.modTime)
        lay2_1.addRow(_('Note history:'), self.hisTime)
        lay2_1.addRow(_('Time be inserted:'), self.insTime)
        lay2_1.addRow(_('Date be inserted:'), self.insDate)
        lay2_1.addRow('', showTime)
        groupBox2_0 = QGroupBox(_('Time Format'))
        groupBox2_0.setLayout(lay2_1)
        #鋪設第2頁總Layout
        lay2 = QFormLayout()
        lay2.setSpacing(10)
        lay2.addRow(groupBox2_0)
        page2 = QWidget()
        page2.setLayout(lay2)

        #鋪設第3頁Layout : Display
        label3_1 = QLabel(_('Inner-title format:\nYou can use {$NOTENAME}、{$PARENTNAME} and some html tags...'))
        label3_1.setWordWrap(True)

        lay3_1 = QFormLayout()
        lay3_1.addRow(_('Show the inner-title:'), self.showInnerTitle)
        lay3_1.addRow(_('Instant char-count update:'), self.showInstantCharcount)
        lay3_1.addRow(label3_1)
        lay3_1.addRow(self.innerTitleFormat)
        lay3_1.addRow(showIT)
        groupBox3_1 = QGroupBox(_('Inner Title'))
        groupBox3_1.setLayout(lay3_1)

        lay3 = QFormLayout()
        lay3.addRow(_('Show char-count:'), self.showCharcount)
        lay3.addRow(_('Trace all page\'s scroll position:'), self.traceScrollPos)
        lay3.addRow(_('Never refresh the listview:'), self.dontRefreshListview)
        lay3_1 = QHBoxLayout()
        lay3_1.addWidget(self.useCSS)
        lay3_1.addWidget(self.selectCSS)
        lay3_1.addWidget(self.editCSSButton)
        lay3.addRow(_('Use CSS:'), lay3_1)
        lay3.addItem(QSpacerItem(20,20))
        lay3.addRow(_('Editor\'s default font:'), self.font)
        lay3.addRow(_('Editor\'s text size multiplier:'), self.textMultiplier)
        lay3.addItem(QSpacerItem(20,20))
        lay3.addRow(QLabel(_('Select LoNote\'s language (Need restart):')))
        lay3.addRow('', self.language)
        lay3.addItem(QSpacerItem(20,20))
        lay3.addRow(groupBox3_1)
        page3 = QWidget()
        page3.setLayout(lay3)

        #鋪設第4頁Layout : Other
        lay4 = QFormLayout()
        lay4.addRow(_('When book was closed, export as a website:'), self.exportToHTMLWhenClose)
        lay4.addRow(_('Let HTML export file to use editor\'s font:'), self.exportEditorFont)
        lay4.addRow(_('Open the HTML file after export:'), self.openAfterExportToHTML)
        lay4.addRow(_('Use multi-processing mode (Experimantal):'), self.useMultiprocessing)
        lay4.addItem(QSpacerItem(20,20))
        lay4.addRow(QLabel(_('Convert a old notebook (version < 1.0.0) to a new one.')))
        lay4.addRow(_('Select a old notebook:'), self.convertButton)
        page4 = QWidget()
        page4.setLayout(lay4)

        #鋪設第5頁Layout : ImageFormat
        #鋪設插入圖片設定用的GroupBox與Layout
        lay5_1 = QFormLayout()
        label5_1 = QLabel(_('You can use {$IMAGE}、{$FILENAME} and some html tags...'))
        label5_1.setWordWrap(False)
        lay5_1.addRow(label5_1)
        lay5_1.addRow(self.insImage)
        lay5_1.addRow(_('Insert width:'), self.insImageWidth)
        lay5_1.addRow(_('Resize the files:'), self.insImageSrcResizeEnable)
        lay5_1.addRow(_('Resize quality (-1 = default):'), self.insImageSrcResizeQuality)
        lay5_1.addRow(showImage)
        #lay5_1.setSizeConstraint(QLayout.SetFixedSize)
        groupBox5_1 = QGroupBox(_('Images Insert Mode'))
        groupBox5_1.setLayout(lay5_1)
        #鋪設第5頁總Layout
        lay5 = QFormLayout()
        lay5.setSpacing(10)
        lay5.addRow(groupBox5_1)
        page5 = QWidget()
        page5.setLayout(lay5)

        #將所有頁面加入設定對話盒
        tab = QTabWidget()
        tab.addTab(page1, _('Data'))
        tab.addTab(page2, _('Time Format'))
        tab.addTab(page5, _('Image Format'))
        tab.addTab(page3, _('Display'))
        tab.addTab(page4, _('Other'))
        vl = QVBoxLayout()
        vl.addWidget(tab)
        #將底部按鈕加入對話盒
        vl.addWidget(self.acceptButton)
        self.setLayout(vl)

        #美化與插圖
        styleSheet = '.QWidget{ background-image: url({$PIC}); background-repeat: no; background-position: right bottom}'.replace('{$PIC}', path.icons.fairy)
        page1.setStyleSheet(styleSheet);

    def reSet(self, status):
        '''透過外來的status，將內容的「數值」部份給初始化'''
        self.status = status
        #第1頁相關參數設定
        if status['VCS_ENABLE']:
            self.vcsEnable.setCheckState(Qt.Checked)
        else:
            self.vcsEnable.setCheckState(Qt.Unchecked)

        self.vcsPeriod.setValue(int(status['AUTOBACKUP_PERIOD']/(60*60)))
        self.vcsLenChange.setValue(status['AUTOBACKUP_LENCHANGE'])

        if status['AUTOBACKUP_LEVENSHTEIN']:
            self.vcsLevenshtein.setCheckState(Qt.Checked)
        else:
            self.vcsLevenshtein.setCheckState(Qt.Unchecked)

        if status['AUTOREMOVE_UNUSED_EMBEDDED_FILES']:
            self.autoRemoveUnusedEmbeddedFiles.setCheckState(Qt.Checked)
        else:
            self.autoRemoveUnusedEmbeddedFiles.setCheckState(Qt.Unchecked)

        self.autosavePeriod.setValue(status['AUTOSAVE_PERIOD'])

        #第2頁相關參數設定
        self.creTime.setText(status['TIMEFORMAT_CREATED'])
        self.modTime.setText(status['TIMEFORMAT_MODIFIED'])
        self.hisTime.setText(status['TIMEFORMAT_HISTORY'])
        self.insDate.setText(status['INSERTFORMAT_DATE'])
        self.insTime.setText(status['INSERTFORMAT_TIME'])

        #第3頁相關參數設定
        if status['SHOW_INNERTITLE']:
            self.showInnerTitle.setCheckState(Qt.Checked)
        else:
            self.showInnerTitle.setCheckState(Qt.Unchecked)

        self.innerTitleFormat.setText(status['INNERTITLE_FORMAT'])

        if status['SHOW_INSTANT_CHARCOUNT']:
            self.showInstantCharcount.setCheckState(Qt.Checked)
        else:
            self.showInstantCharcount.setCheckState(Qt.Unchecked)

        if status['SHOW_CHARCOUNT']:
            self.showCharcount.setCheckState(Qt.Checked)
        else:
            self.showCharcount.setCheckState(Qt.Unchecked)

        if status['TRACE_SCROLLPOS']:
            self.traceScrollPos.setCheckState(Qt.Checked)
        else:
            self.traceScrollPos.setCheckState(Qt.Unchecked)

        if status['DONT_REFRESH_LISTVIEW']:
            self.dontRefreshListview.setCheckState(Qt.Checked)
            self.oldDontRefStatus = True
        else:
            self.dontRefreshListview.setCheckState(Qt.Unchecked)
            self.oldDontRefStatus = False

        if status['USE_CSS']:
            self.useCSS.setCheckState(Qt.Checked)
        else:
            self.useCSS.setCheckState(Qt.Unchecked)

        #使用CSS設定
        self.selectCSS.clear()
        for p in glob.iglob(os.path.join(cssDir, '*.css')):
            self.selectCSS.addItem(os.path.basename(p))
        index = self.selectCSS.findText(status['CSS_FILE'])
        self.selectCSS.setCurrentIndex(index)

        #字體放大倍率設定
        self.textMultiplier.setValue(status['EDITOR_TEXT_SIZE_MULTIPLIER'])

        #使用語言設定
        langCode = translate.loadLocaleSetting()
        i = 0
        index = 0
        self.language.clear()
        for data in translate.validLanguages:
            self.language.addItem(data[1])
            if langCode == data[0]:
                index = i
            i += 1
        self.language.setCurrentIndex(index)

        #使用字型設定
        self.font.clear()
        self.font.addItem(_('= Unassigned ='))
        self.font.addItems(QFontDatabase().families())
        index = self.font.findText(status['EDITOR_FONT_ST'])
        if index == -1:
            self.font.setCurrentIndex(0)
        else:
            self.font.setCurrentIndex(index)

        #第4頁相關參數設定
        if status['OPEN_AFTER_EXPORT_TO_HTML']:
            self.openAfterExportToHTML.setCheckState(Qt.Checked)
        else:
            self.openAfterExportToHTML.setCheckState(Qt.Unchecked)

        if status['EXPORT_EDITOR_FONT']:
            self.exportEditorFont.setCheckState(Qt.Checked)
        else:
            self.exportEditorFont.setCheckState(Qt.Unchecked)

        if status['EXPORT_TO_HTML_WHEN_CLOSE']:
            self.exportToHTMLWhenClose.setCheckState(Qt.Checked)
        else:
            self.exportToHTMLWhenClose.setCheckState(Qt.Unchecked)

        if status['MULTIPROCESSING']:
            self.useMultiprocessing.setCheckState(Qt.Checked)
        else:
            self.useMultiprocessing.setCheckState(Qt.Unchecked)

        #第5頁相關參數設定
        self.insImage.setText(status['INSERTFORMAT_IMAGE'])
        self.insImageWidth.setValue(status['INSERTFORMAT_IMAGE_WIDTH'])

        if status['INSERTFORMAT_IMAGE_SRC_RESIZE_ENABLE']:
            self.insImageSrcResizeEnable.setCheckState(Qt.Checked)
        else:
            self.insImageSrcResizeEnable.setCheckState(Qt.Unchecked)

        self.insImageSrcResizeQuality.setValue(status['INSERTFORMAT_IMAGE_SRC_RESIZE_QUALITY'])

    def accept(self):
        '''按下確認按鈕之後的行動'''
        #第1頁參數設定
        if self.vcsEnable.checkState() == Qt.Checked:
            self.status['VCS_ENABLE'] = True
        else:
            self.status['VCS_ENABLE'] = False

        self.status['AUTOBACKUP_PERIOD'] = self.vcsPeriod.value()*(60*60)
        self.status['AUTOBACKUP_LENCHANGE'] = self.vcsLenChange.value()

        if self.vcsLevenshtein.checkState() == Qt.Checked:
            self.status['AUTOBACKUP_LEVENSHTEIN'] = True
        else:
            self.status['AUTOBACKUP_LEVENSHTEIN'] = False

        if self.autoRemoveUnusedEmbeddedFiles.checkState() == Qt.Checked:
            self.status['AUTOREMOVE_UNUSED_EMBEDDED_FILES'] = True
        else:
            self.status['AUTOREMOVE_UNUSED_EMBEDDED_FILES'] = False
        self.status['AUTOSAVE_PERIOD'] = self.autosavePeriod.value()

        #第2頁參數設定
        self.status['TIMEFORMAT_CREATED'] = self.creTime.text()
        self.status['TIMEFORMAT_MODIFIED'] = self.modTime.text()
        self.status['TIMEFORMAT_HISTORY'] = self.hisTime.text()
        self.status['INSERTFORMAT_DATE'] = self.insDate.text()
        self.status['INSERTFORMAT_TIME'] = self.insTime.text()

        #第3頁參數設定
        if self.showInnerTitle.checkState() == Qt.Checked:
            self.status['SHOW_INNERTITLE'] = True
        else:
            self.status['SHOW_INNERTITLE'] = False

        self.status['INNERTITLE_FORMAT'] = self.innerTitleFormat.text()

        if self.showInstantCharcount.checkState() == Qt.Checked:
            self.status['SHOW_INSTANT_CHARCOUNT'] = True
        else:
            self.status['SHOW_INSTANT_CHARCOUNT'] = False

        if self.showCharcount.checkState() == Qt.Checked:
            self.status['SHOW_CHARCOUNT'] = True
        else:
            self.status['SHOW_CHARCOUNT'] = False

        if self.traceScrollPos.checkState() == Qt.Checked:
            self.status['TRACE_SCROLLPOS'] = True
        else:
            self.status['TRACE_SCROLLPOS'] = False

        if self.dontRefreshListview.checkState() == Qt.Checked:
            self.status['DONT_REFRESH_LISTVIEW'] = True
            if self.oldDontRefStatus != True:
                self.parent.genListView(1)
        else:
            self.status['DONT_REFRESH_LISTVIEW'] = False

        if self.useCSS.checkState() == Qt.Checked:
            self.status['USE_CSS'] = True
        else:
            self.status['USE_CSS'] = False
        self.status['CSS_FILE'] = self.selectCSS.currentText()

        self.status['EDITOR_TEXT_SIZE_MULTIPLIER'] = self.textMultiplier.value()

        translate.saveLanguageFile(translate.validLanguages[self.language.currentIndex()][0])

        if self.font.currentIndex() == 0:
            self.status['EDITOR_FONT_ST'] = ''
        else:
            self.status['EDITOR_FONT_ST'] = self.font.currentText()

        #第4頁相關參數設定
        if self.openAfterExportToHTML.checkState() == Qt.Checked:
            self.status['OPEN_AFTER_EXPORT_TO_HTML'] = True
        else:
            self.status['OPEN_AFTER_EXPORT_TO_HTML'] = False

        if self.exportEditorFont.checkState() == Qt.Checked:
            self.status['EXPORT_EDITOR_FONT'] = True
        else:
            self.status['EXPORT_EDITOR_FONT'] = False

        if self.exportToHTMLWhenClose.checkState() == Qt.Checked:
            self.status['EXPORT_TO_HTML_WHEN_CLOSE'] = True
        else:
            self.status['EXPORT_TO_HTML_WHEN_CLOSE'] = False

        if self.useMultiprocessing.checkState() == Qt.Checked:
            self.status['MULTIPROCESSING'] = True
        else:
            self.status['MULTIPROCESSING'] = False

        #第5頁相關參數設定
        self.status['INSERTFORMAT_IMAGE'] = self.insImage.text()
        self.status['INSERTFORMAT_IMAGE_WIDTH'] = self.insImageWidth.value()

        if self.insImageSrcResizeEnable.checkState() == Qt.Checked:
            self.status['INSERTFORMAT_IMAGE_SRC_RESIZE_ENABLE'] = True
        else:
            self.status['INSERTFORMAT_IMAGE_SRC_RESIZE_ENABLE'] = False
        self.status['INSERTFORMAT_IMAGE_SRC_RESIZE_QUALITY'] = self.insImageSrcResizeQuality.value()

        #收尾
        #讓parent依據新參數進行內部所需的更新
        self.parent.setAsStatus()
        #可能有調整過History記錄設定，更新歷史記錄列表
        self.parent.genHistoryView(self.parent.bhistory.current().editor)
        #關閉對話盒
        self.close()

    def convert(self):
        '''將0.4.6以前的舊版本筆記資料轉為新版本的格式'''
        if not dialog.questionDialog(_('Convert a old notebook'),
                _('"Don\'t panic, it won\'t hurt you..."\n\nAll thing you need to do is select the old notebook\'s folder.\n\nContinue?'),
                path.icons.kworking):
            return False

        tPath = QFileDialog.getExistingDirectory(self, caption = _('select notebook folder'))
        if not tPath:
            return False
        if not os.path.isdir(tPath) or not os.path.isfile(os.path.join(tPath,'notebook.xml')) or not os.path.isfile(os.path.join(tPath,'node.xml')) or not os.path.isfile(os.path.join(tPath,'page.html')):
            dialog.infoDialog(_('Convert a old notebook'),
                _('"Ouch!"\n\n"{0}" is not a old notebook folder. Operation cancel...').format(tPath),path.icons.error)
            return False

        index = 1
        while True:
            if not os.path.exists(tPath + '_new' + str(index)):
                break
            index += 1

        oldnote.oldNotebook2sqlite(tPath+'_new'+str(index) ,tPath)
        dialog.infoDialog(_('Convert a old notebook'),
            _('"It Done!"\n\nYour new notebook now place on "{0}", you can change folder\'s name and position by yourself.').format(tPath + '_new' + str(index)),path.icons.khappy)

    def vacuum(self):
        '''壓縮parent當前的資料庫'''
        self.parent.conn.execute('VACUUM')
        self.parent.conn.commit()

    def clearAllHistory(self):
        '''刪光當前筆記本的歷史記錄'''
        if not dialog.questionDialog(_('Remove all History of this notebook'),
                _('"Wait! Do you really want to clear all history of this notebook?"\n\nConfirm?'),
                path.icons.kworking):
            return False
        self.parent.conn.execute('delete from history')
        self.parent.conn.commit()
        self.parent.genHistoryView(self.parent.editor.getID())

    def editCSS(self):
        '''編輯指定的CSS'''
        cssPath = os.path.join(cssDir, self.selectCSS.currentText())
        QDesktopServices.openUrl(QUrl.fromLocalFile(cssPath))
